home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!ts00-and-17
- From: dlmiller@iquest.net (Doug & Rose Miller)
- Subject: Re: Can C save and retreive from disk?
- X-Nntp-Posting-Host: ts00-and-17.iquest.net
- Message-ID: <Do2tDq.EA7@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <4hpd14$hel@lantana.singnet.com.sg>
- Date: Sun, 10 Mar 1996 23:56:46 GMT
-
- Teddy Bear <s7700038@singnet.com.sg> wrote:
- +This is a multi-part message in MIME format.
- +
- +---------------------------------300002593617914
- +Content-Transfer-Encoding: 7bit
- +Content-Type: text/plain; charset=us-ascii
- +
- +Can anyone teach me or refer me or help in any way?
- +I need to save to disk and retrieve from disk
- +Can anyone help me
- +The prog goes
- +
- +---------------------------------300002593617914
- +Content-Transfer-Encoding: 7bit
- +Content-Type: text/plain
- +
- +/* This program simply enable the user to enter the particular(s). It will
- + then sort the name in an alphabetical order and display the particular(s)
- + on the screen. It also ensures that the user is able to add and delete
- + the particular(s). */
- +
- +#include <stdio.h>
- +#include <alloc.h>
- +#include <conio.h>
- +#include <string.h>
- +#include <stdlib.h>
- +#define TRUE 1
- +#define FALSE 0
- +
- +typedef struct data{
- + int age;
- + char name[40];
- + char address[100];
- + struct data *next;
- +}dataelm;
- +typedef dataelm* dataptr;
- +
- +void createdata(dataptr *ptr_to_head, dataptr head);
- +int countlink(dataptr head);
- +void sortlink(dataptr head);
- +dataptr searchlink(dataptr head, char *wanted);
- +void display(dataptr head);
- +void save(dataptr headptr, char file[20]);
- +void read(char file[20]);
- +dataptr clearlink(dataptr head);
- +dataptr addnode(dataptr head);
- +dataptr delnode(dataptr head);
- +void check(dataptr head);
- +
- +int main()
- +{
- + char *sname, option;
- + int checker = 0;
- + dataptr ptr, *ptr_to_head, head, tail;
- +
- + head = NULL; /* assigns head with NULL, starting of link list */
- + option = '1';
- + do
- + {
- + clrscr();
- + printf("\n\nÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ MAIN MENU ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ\n");
- + printf("\n1) Adding of particular(s).\n");
- + printf("2) Adding of new particular(s).\n");
- + printf("3) Deleting of current particular(s).\n");
- + printf("4) Display all the particular(s) entered.\n");
- + printf("5) Exit the program.\n");
- + printf("\nPlease enter your choice : ");
- + if(option < '0' || option > '6')
- + printf("\nInvaild option. Please re-enter.");
- + option = getche();
- + switch(option)
- + {
- + case '1' : if(checker != 0)
- + {
- + printf("\a");
- + printf("\n\nYou had create a link list previously.");
- + printf("\nIf you proceed, the previous data will be lost.");
- + printf("\n\nEnter a 'Y' to proceed.");
- + printf("\nEnter ESC to return to main menu ");
- + if((toupper(getch())) != 'Y')
- + break;
- + else
- + clearlink(head);
- + }
- + createdata(ptr_to_head, NULL);
- + head = *ptr_to_head;
- + sortlink(head);
- + display(head);
- + checker = 1;
- + break;
- + case '2' : if(checker != 1)
- + {
- + printf("\a");
- + printf("\n\nYou have not yet create a link list.");
- + printf("\nPlease choose option '1'.");
- + printf("\n\nPress any key to continue.");
- + getch();
- + break;
- + }
- + head = addnode(head);
- + checker = 1;
- + display(head);
- + break;
- + case '3' : if(checker!=1)
- + {
- + printf("\a");
- + printf("\n\nYou have not yet create a link list.");
- + printf("\nPlease choose option '1'.");
- + printf("\n\nPress any key to continue.");
- + getch();
- + break;
- + }
- + display(head);
- + head = delnode(head);
- + display(head);
- + if(head == NULL)
- + checker = 0;
- + break;
- + case '4' : display(head);
- + break;
- + case '5' : printf("\n\nHave a nice day. BYE!\n");
- + printf("Press any key to end...");
- + getch();
- + exit(0);
- + }
- + }
- + while(option != '5');
- + return 0;
- +}
- +
- +void createdata(dataptr *ptr_to_head, dataptr head)
- +/* create a link of the telephone list */
- +{
- + dataptr temp, last;
- + char ans;
- + int elm_size = sizeof(dataelm);
- + do
- + {
- + temp = (dataptr)malloc(elm_size);
- + clrscr();
- + printf("\n\nÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ PARTICULAR CREATING ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ\n");
- + printf("\nEnter name to be added : ");
- + gets(temp->name);
- + printf("Enter Age : ");
- + scanf("%d",&temp->age);
- + fflush(stdin);
- + printf("Enter Address : ");
- + gets(temp->address);
- +
- + if(head == NULL)
- + {
- + head = temp; /* assigns the address of dataptr to head */
- + last = temp;
- + }
- + else
- + {
- + last->next=temp;
- + last = temp;
- + }
- + printf("\nAny more you would like to enter ? <Y/N> : ");
- + ans=toupper(getch());
- + }
- + while(ans != 'N');
- + last->next = NULL;
- + *ptr_to_head = head;
- +}
- +
- +void sortlink(dataptr head)
- +/* sort the link in an alphabetical order */
- +{
- + dataptr front, back;
- + struct data temp;
- + int pass, cnt, condition;
- + int element;
- + element = countlink(head);
- + pass = 0;
- + do
- + {
- + pass++;
- + condition = TRUE;
- + front = head->next;
- + back = head;
- + for(cnt = 0; cnt < element - pass; cnt++)
- + {
- + /* compare the character */
- + if((strcmp((back->name), (front->name))) > 0)
- + {
- + condition = FALSE;
- + strcpy(temp.name, back->name);
- + temp.age = back->age;
- + strcpy(temp.address, back->address);
- + strcpy(back->name, front->name);
- + back->age = front->age;
- + strcpy(back->address, front->address);
- + strcpy(front->name, temp.name);
- + front->age = temp.age;
- + strcpy(front->address, temp.address);
- + }
- + back = front;
- + front = front->next;
- + }
- +
- + ... blah blah blah ...
- Try debugging your program.
-